//
//  ZYSetViewController.swift
//  WeiBoAPP
//
//  Created by ios001 on 2023/12/27.
//  Copyright © 2023 zxf. All rights reserved.
//

import UIKit

class ZYSetViewController: ZFBaseViewController {
    
    var dataList = [Any]()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        title = "设置"
        
        dataList = ["设置","关于","缓存"]
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if (UserDataConfig.shared.isLogin == true){
            self.tableView?.tableFooterView = self.footerView

        }else{
            self.tableView?.tableFooterView = nil
        }
    }
    
    override func setupTableView() {
        super.setupTableView()
        self.tableView?.tableFooterView = self.footerView
        
    }
    lazy var footerView: UIView = {
        let footerView = UIView.init(frame: CGRect(x: 0, y: 0, width: WB_SCREED_WIDTH, height: 60))
        let loginOutBtn = UIButton(type: .custom)
        loginOutBtn.setTitle("退出登录", for: .normal)
        loginOutBtn.setTitleColor(UIColor.red, for: .normal)
        loginOutBtn.layer.borderWidth = 1
        loginOutBtn.layer.borderColor = UIColor.red.cgColor
        loginOutBtn.layer.cornerRadius = 5
        loginOutBtn.addTarget(self, action: #selector(loginOutBtnAction), for: .touchUpInside)
        footerView.addSubview(loginOutBtn)
        loginOutBtn.snp.makeConstraints { make in
            make.width.equalTo(170)
            make.height.equalTo(40)
            make.centerX.equalTo(footerView)
            make.top.equalTo(10)
        }
        
        return footerView
    }()
    
    @objc func loginOutBtnAction () {
        
        let alert = UIAlertController(title: "温馨提示", message: "您是否确定要退出登录?", preferredStyle: .alert)
        let canelAction = UIAlertAction(title: "取消", style: .cancel) { _ in
            
        }
        let okAction = UIAlertAction(title: "确定", style: .default ) { _ in
            self.loginOut()
            self.navigationController?.popViewController(animated: true)
        }
        
        alert.addAction(canelAction)
        alert.addAction(okAction)
        self.present(alert, animated: true)
    }
    
}

extension ZYSetViewController {
 
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataList.count
    }
    
 
  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      
      var cell:UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: "cell")
      if cell == nil {
          cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
      }
      let str = dataList[indexPath.row] as? String
      cell?.textLabel?.text =  str
      
      
      return cell!
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        print("\(indexPath)")
    }
    
}
